package de.slothsoft.commons.swing.util;

import static de.slothsoft.commons.debug.Debug.DEBUG;

import java.awt.Component;

import javax.swing.JOptionPane;

import de.slothsoft.commons.res.CommonMessages;

public class ErrorUtil {

	public static void showError(Component parent, Exception e) {
		String message = e.getLocalizedMessage();
		if (message != null) {
			message = e.getMessage();
		}
		if (message != null) {
			message = e.getClass().getCanonicalName();
		}
		if (DEBUG) {
			e.printStackTrace();
		}
		showError(parent, message);
	}

	public static void showError(Component parent, String message) {
		JOptionPane.showMessageDialog(parent, message, CommonMessages.getString("ErrorUtil.errorTitle"),
				JOptionPane.ERROR_MESSAGE);
	}
}
